{include file="admin@public/header" /}

<style>
	#matchCon {
		width: 160px;
	}

	.url-box {
		padding: 5px 10px;
		line-height: 26px;
		cursor: pointer;
	}

	.url-box a {
		margin-right: 5px;
	}
</style>


<div class="bill-ser-top">
	<ul class="ul-inline cf">
		<li>
			<input type="text" id="matchCon" class="ui-input ui-input-ph" placeholder="请输入单据号或制单人姓名"
				style="width: 190px;">
		</li>
		<li>
			<label>日期:</label>
			<input type="date" id="datew" class="ui-input " value="{$mon_start}" style="width: 125px;">
			<i>-</i>
			<input type="date" id="dateo" class="ui-input " value="{$today}" style="width: 125px;">
		</li>
		<li><a class="mrb more ui-btn" id="moreCon" onclick="heightSear('/admin/basic/hight_search.html?o_type={$o_type}','高级搜索','815px','460px')">高级搜索</a><a class="ui-btn mrb ui-btn-search" id="search">查询</a></li>
	</ul>
</div>
<div class="wrapper btc">
	<div class="bill-ser-botm cf">
		<div class="ui-config-box">
			<span id="config" class="ui-config"><a href="#" class="ui-icon-config-new"></a>列设置</span>
		</div>
		<div class="fr">

			<a class="ui-btn-bill ui-btn-add" id="add"
				onclick="addPage('/money/oriinc/add.html','salesOrder','其它收入单')">新增</a>

			<div class="ui-btn-menu ml10">
				<a class="ui-btn-bill ui-btn-hl menu-btn mrb" style="width: 40px;padding-right: 14px;" href="#"
					id="shenhe">审核<b></b></a>
				<div class="con hl more-operate-con" style="margin-left: 0px;font-size: 14px;width: 55px;padding: 6px;">
					<ul class="more-operate cf" style="border-style:dashed; border-width:1px; border-color:#ccc;">
						<li><a href="#" id="reshenhe">反审核</a></li>
					</ul>
				</div>
			</div>
			<div class="ui-btn-menu ml10">
				<a class="ui-btn-bill ui-btn-hl menu-btn mrb" href="#" id="print" target="_blank"
					href="javascript:void(0);">打印<b></b></a>
				<div class="con hl more-operate-con" style="margin-left: 0px;font-size: 14px;width: 54px;padding: 3px;">
					<ul class="more-operate cf" style="border-style:dashed; border-width:1px; border-color:#ccc;">
						<li style="padding-left: 8px;"><a href="#" id="printSet" href="javascript:void(0);">设置</a></li>
					</ul>
				</div>
			</div>
			<div class="ui-btn-menu ml10">
				<a class="ui-btn-bill ui-btn-hl menu-btn mrb" style="width: 40px;padding-right: 7px;" href="#"
					id="import"  href="javascript:void(0);">导入<b></b></a>
				<div class="con hl more-operate-con" style="margin-left: 0px;font-size: 14px;width: 54px;padding: 3px;">
					<ul class="more-operate cf" style="border-style:dashed; border-width:1px; border-color:#ccc;">
						<li style="padding-left: 8px;"><a href="#" id="export"
								href="javascript:void(0);">导出</a></li>
					</ul>
				</div>
			</div>
			<a href="#" class="ui-btn-bill ui-btn-hl ml10" id="del">删除</a>
		</div>
	</div>
	<div class="grid-wrap">
		<table id="grid">
		</table>
		<div id="page"></div>
	</div>
</div>


<script type="text/javascript">
	$("#export").click(function (){
		var rowData = $("#grid").getRowData();
	    var rowid = '';
	    rowData.forEach(function(a,b,c){
	    	rowid += a['id']+' ';
	    })
	    console.log(rowid);
		window.location.href = '/money/Oriinc/export?rowid='+rowid;
	})
	$(document).ready(function () {
		function b(a) {
			//var b = a.join('<p class="line" />');
			var b = a.join('<p class="combineOrNot combineHeight line" style="display: block;    zoom: 1;height: 1px;font-size: 12px;line-height: 2;margin: 3px 2px;overflow:visible">');
			return b;
		}
		function pipei(t, i, e) {
			if (1 == t.length) return t[0];
			if (1 < t.length) {
				for (var n = [], a = 0; a < t.length; a++) n[a] = 0 == a ? "<p class='combineHeight' style='margin-bottom: 10px;'>" + t[a] + '</p><span class="number_sku add"></span>' : '<p class="combineOrNot combineHeight" style="margin-top: 10px;">' + t[a] + "</p>";
				return n.join('<p class="line combineOrNot" />');
			}
			return t;
		}
		$("#grid").jqGrid({
			url: '/money/oriinc/index.html?ajax=100',
			datatype: "json",//数据来源，本地数据（local，json,jsonp,xml等）
			height: '90%',//高度，表格高度。可为数值、百分比或'auto'
			//width: Public.setGrid().w,
			//height: Public.setGrid().h,
			colNames: ["操作", "单据日期", "单据编号", "客户名称", "金额", "制单人", "审核人", "已收金额", "收款状态", "备注", "打印次数", "订单状态", 'ID'],
			colModel: [
				{ name: '', width: 80, formatter: actions },
				{ name: 'dj_time', width: 90, },
				{ name: 'sn', width: 120 },
				{ name: 'customer_name', width: 120 },
				{ name: 'jine', width: 80 },//金额
				{ name: 'add_user_name', width: 80 },
				{ name: 'shenhe_user_name', width: 80 },
				{ name: 'now_jine', width: 80 },//已收金额
				{ name: 'sk_status', width: 80 },//收款状态
				{ name: 'mark', width: 250 },
				{ name: 'print_number' },
				{ name: "status", hidden: true },//订单状态
				{ name: 'id', hidden: true },
			],
			rownumbers: true, //自增序号
			multiselect: true,//自带多选
			multiboxonly: true,//变成单选
			sortable: true,  //排序
			rowNum: 10,
			rowList: [10, 20, 30],
			sortname: 'id',
			sortorder: "desc",
			pagerpos: "left",//分页位置
			pgbuttons: true,//翻页按钮
			pagination: true,
			altRows: !0,
			gridview: !0,
			shrinkToFit: !1,
			cellLayout: 8,
			autowidth: !0,
			pager: "#page",
			viewrecords: !0,
			cmTemplate: {
				sortable: !1,
				title: !1
			},
			loadError: function (t, e, i) {
				parent.Public.tips({
					type: 1,
					content: "操作失败了哦，请检查您的网络链接！"
				})
			},
			// 合计
			footerrow: true,
			gridComplete: function () {

				var jines = parseFloat($("#grid").getCol('jine', false, 'sum')).toFixed(2);//销售金额
				var now_jines = parseFloat($("#grid").getCol('now_jine', false, 'sum')).toFixed(2);//销售数量
				$("#grid").footerData('set', { "customer_name": '合计', "jine": jines, "now_jine": now_jines });
				var grid = $("#grid");
				var col_hs = grid.getCol('col_h', false);//获取某一列
				var ids = grid.getDataIDs();

				var rowDatas = grid.jqGrid("getRowData");//获取所有行的数据
				//alert(col_hs);
				for (var i = 0; i < ids.length; i++) {
					//设置行高
					grid.setRowData(ids[i], false, { height: 40 * col_hs[i] });
					var rowData = rowDatas[i];
					if (rowData.status == "0") {
						$("#" + ids[i] + " td").css("color", "#999999");
					}
				}
			},
			//双击表格行事件
			ondblClickRow: function (row) {
				var rowData = $('#grid').jqGrid('getRowData', row);
				console.log(rowData.id);
				//var start_date = $('input[name=start_date]').val();
				//var end_date = $('input[name=end_date]').val();
				parent.tab.addTabItem({
					tabid: "money_inc",
					text: "其它收入单",
					url: "/money/oriinc/details.html?order_id=" + rowData.id,
				})

			}
		});
	});


	function cLink(cellvalue, options, rowObject) {
		if (rowObject.status == 0) {
			return '<span class="set-status open" data-delete="false" onclick="switchs(this,' + rowObject.id + ')"><span class="ui-icon-circle"></span></span>';
		} else {
			return '<span class="set-status close" data-delete="false" onclick="switchs(this,' + rowObject.id + ')"><span class="ui-icon-circle"></span></span>';
		}
	}

	function actions(cellvalue, options, rowObject) {
		return '<div class="operating"><span class="ui-icon ui-icon-pencil" onclick="addPage(\'/money/oriinc/details.html?order_id=' + rowObject.id + '\',\'money_inc\',\'其它收入单\')">修改</span> <span class="ui-icon ui-icon-trash" onclick="del(' + rowObject.id + ')">删除</span></div>';
	}

	function switchs(obj, id) {
		if ($(obj).hasClass("open")) {
			$(obj).removeClass("open");
			$(obj).addClass("close");
			status = 1;
		} else {
			$(obj).removeClass("close");
			$(obj).addClass("open");
			status = 0;
		}

		$.ajax({
			type: 'POST',
			url: "save.html",
			data: { id: id, status: status },
			dataType: "json",
			async: false,
			error: function (request) {
				layer.msg("发送请求失败！");
			},
			success: function (data) {
				if (data.status == 1) {
					layer.msg(data.msg);
				} else {
					layer.msg(data.msg);
				}

			}
		});
	}




</script>

<script type="text/javascript">

	//获取表格选中数据
	function selectdata() {
		var rowid = $("#grid").jqGrid("getGridParam", "selrow");
		// console.log(rowid);
		var rowData = jQuery("#grid").jqGrid("getRowData", rowid);
		// console.log(rowData);
		var arr = new Array();
		arr['id'] = rowid;
		arr['data'] = rowData;
		return arr;
	}

	// 删除按钮
	$("#del").click(function () {
		var xz = selectdata();
		if (xz['id'] == null) {
			layer.msg("请选中要删除的数据");
			return false;
		}
		order_del(xz['id']);
	})
	// 删除方法
	function order_del($id) {
		layer.confirm('确认要删除吗？', function (index) {
			$.ajax({
				url: '{:url("del")}?id=' + $id,
				beforeSend: function () {
					load = layer.load(1);
				},
				success: function (data) {
					if (data.status == 1) {
						parent.layer.close();
						layer.msg('已删除!', { time: 1000 });
						window.location.reload();
						parent.layer.closeAll();
					} else {
						layer.msg(data.msg, { time: 1000 });
					}
				}
			}).always(function () {
				layer.close(load);
			});
		});

	}

	// 审核按钮
	$("#shenhe").click(function () {
		var xz = selectdata();
		if (xz['id'] == null) {
			layer.msg("请先选中要操作的数据");
			return false;
		}
		order_shenhe(xz['id'], 1);
	})

	// 反审核按钮
	$("#reshenhe").click(function () {
		var xz = selectdata();
		if (xz['id'] == null) {
			layer.msg("请先选中要操作的数据");
			return false;
		}
		order_shenhe(xz['id'], 2);
	})

	// 审核方法--1,审核 2，反审核
	function order_shenhe($id, $type) {

		$.ajax({
			url: '{:url("shenhe")}?id=' + $id + '&type=' + $type,
			beforeSend: function () {
				load = layer.load(1);
			},
			success: function (data) {
				if (data.status == 1) {
					layer.msg(data.msg, { time: 1000 });
					window.location.reload();

				} else {
					layer.msg(data.msg, { time: 1000 });
				}
			}

		}).always(function () {
			layer.close(load);
		});
	}
	//搜索
	$("#search").click(function () {

		var matchCon = $("#matchCon").val();
		var datew = $("#datew").val();
		var dateo = $("#dateo").val();

		$("#grid").jqGrid('setGridParam', {
	        datatype: 'json',
	        //发送数据 
	        postData: { 'ajax': '100', 'matchCon':matchCon,'datew':datew,'dateo':dateo,'search':0 },
	        page: 1
    	}).trigger("reloadGrid"); //重新载入

		//删除加载缓存	
		var postData = $("#grid").jqGrid("getGridParam", "postData");
	　　	$.each(postData, function (k, v) { 
	　　    delete postData[k];  
	　　});

	});
	// 高级搜索
	function heightSear(url, title, width, height){
		layer.open({
			type: 2,
			title: title,
			shadeClose: true,
			shade: 0.3,
			maxmin: true, //开启最大化最小化按钮
			btn: ['重置', '查询', '关闭'],
			area: [width, height],
			content: url,
			btn1: function (index, layero) {
				document.getElementById("layui-layer-iframe"+index).contentWindow.location.reload();
				return false;
			},
			btn2:function(index, layero){
				// layer.close(index);

				var fromDate=layero.find("iframe")[0].contentWindow.$("#filter-fromDate").val();//高级搜索开始时间
				var toDate=layero.find("iframe")[0].contentWindow.$("#filter-toDate").val();//高级搜索结束时间
				var remarkCon=layero.find("iframe")[0].contentWindow.$("#remarkCon").val();//备注
				var customer_id=layero.find("iframe")[0].contentWindow.$("#customer_id").val();//客户
				var usersCreatId=layero.find("iframe")[0].contentWindow.$("#usersCreatId").val();//制单人
				var usersModifyId=layero.find("iframe")[0].contentWindow.$("#usersModifyId").val();//最后修改人
				var courierNumberInput=layero.find("iframe")[0].contentWindow.$("#courierNumberInput").val();//快递单号
				var usersChecksId=layero.find("iframe")[0].contentWindow.$("#usersChecksId").val();//审核人
				var checkStatusId=layero.find("iframe")[0].contentWindow.$("#checkStatusId").val();//审核状态

				$("#grid").jqGrid('setGridParam', {
			        datatype: 'json',
			        postData: { 
			        	'ajax':'100',
			        	'search':'1',
						'fromDate':fromDate,
						'toDate':toDate,
						'remarkCon':remarkCon,
						'customer_id':customer_id,
						'usersCreatId':usersCreatId,
						'usersModifyId':usersModifyId,
						'courierNumberInput':courierNumberInput,
						'usersChecksId':usersChecksId,
						'checkStatusId':checkStatusId
			        }, //发送数据 
			        page: 1
			    }).trigger("reloadGrid"); //重新载入
			    var postData = $("#grid").jqGrid("getGridParam", "postData");
			　　　　$.each(postData, function (k, v) { 
			　　　　　　delete postData[k];  
			　　　　});
				return false;
			},
			btn3:function(index, layero){
				layer.close(index);
				return false;
			},
			success: function (layero, index) {
	            //渲染按钮样式
				$(".layui-layer-btn .layui-layer-btn0").css({
					"background": "-webkit-gradient(linear,0 0,0 100%,from(#f2f2f2),to(#f4f4f4))",
					"float": "left",
					"color":"#555",
					"border":"1px solid #c1c1c1",
				});
				$(".layui-layer-btn .layui-layer-btn1").css({
					"background": "linear-gradient(to bottom,#4dc2e6 0,#38B3EB 100%)",
					"color":"#fff",
					"border":"1px solid #38B3EB"

				});
	        }
		});
	};
</script>

{include file="admin@public/footer" /}